package com.example.hotelsystem.controller.userrolepower;


import code.CodeError;
import com.example.hotelsystem.entity.Code;
import com.example.hotelsystem.entity.Power;
import com.example.hotelsystem.entity.User;
import com.example.hotelsystem.result.Result;
import com.example.hotelsystem.service.PowerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lee
 * @since 2020-10-13
 */
@RestController
@RequestMapping("/hotelsystem/power")
@Api(tags = "权限控制器")
public class PowerController {

    @Autowired
    PowerService powerService;

    @PostMapping("/list")
    @ApiOperation("查出该系统的所有权限")
    public Result PowerList(){
        List<Power> list = powerService.list();
        if(list!=null){
            return Result.success(list);
        }else{
            return Result.error(CodeError.POWER_LIST_NULL,"权限list为空");
        }
    }

    @PostMapping("/add")
    @ApiOperation("新增权限")
    public Result AddPower(String powerName){
        Power power = new Power();
        power.setPowerName(powerName);
        boolean isAdd = powerService.save(power);
        if(isAdd){
            return Result.success("新增权限成功");
        }else{
            return Result.error(CodeError.POWER_SAVE_FAIL,"新增权限失败");
        }
    }


}

